home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 495 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.8 KB

  1. From: clamage@Eng.Sun.COM (Steve Clamage)
  2. Message-ID: <4ftia0$c5s@engnews1.Eng.Sun.COM>
  3. X-Original-Date: 14 Feb 1996 20:56:32 GMT
  4. Path: in2.uu.net!bounce-back
  5. Date: 15 Feb 96 00:46:17 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. Newsgroups: comp.std.c++
  8. Subject: Re: Initializer w/sizeof() on lhs term, okay o
  9. Organization: Sun Microsystems Inc.
  10. References: <4fqq6l$qcr@venus.roc.csci.csc.com>
  11. Reply-To: clamage@Eng.Sun.COM
  12. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  13.     iQBFAgUBMSKCd+EDnX0m9pzZAQEybwGAk1lAJimToQfDU4RYVm55DPgsGXZYtFxl
  14.     fSppMWu9fcijxNaK6TF9aTtY2hFSDHjl
  15.     =C9v+
  16.  
  17. In article qcr@venus.roc.csci.csc.com, tottinge@csci.csc.com (Tim
  18. Ottinger) writes:
  19.  
  20. >In the following example, the problem is manifest nicely, but the actual
  21. >code fragment is clearly nonsensical.  Forgive this.  I didn't want to go
  22. >chasing down the code again.
  23.  
  24. >It all comes down to a problem where a sizeof() is used on the rhs of an 
  25. >initialization, and it's operating on the object it's initializing:
  26. >
  27. >    someType z  = fred + sizeof(z);
  28. >                ^                  ^^
  29.  
  30. >Of course, I've changed the inherited code to read:
  31. >
  32. >    someType z  = fred + sizeof(someType);
  33. >                ^                  ^^^^^^^^
  34.  
  35. The original code is valid as shown. The point of declaration of a name is
  36. immediately after its complete declarator and before its initializer (if any),
  37. with a few exceptions that don't apply to this particular example.
  38.  
  39. Thus, 'z' has been declared by the time you get to the '=', so you can
  40. use 'sizeof(z)' in its initializer. There is no ambiguity, since the size
  41. of z is the size of 'someType', no matter what the value of the initializer.
  42.  
  43. ---
  44. Steve Clamage, stephen.clamage@eng.sun.com
  45. ---
  46. [ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  47.   Contact address: std-c++-request@ncar.ucar.edu.  Moderation policy:
  48.   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html. ]
  49.